import type { LoginResult } from '@/types/member'
import { http } from '@/utils/http'

type LoginWxMinParams = {
  code: string
  encryptedData?: string
  iv?: string
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: LoginWxMinParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin',
    data,
  })
}

/**
 * 小程序登录_内测版
 * @param phoneNumber 模拟手机号码
 */
export const postLoginWxMinSimpleAPI = (phoneNumber: string) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin/simple',
    data: {
      phoneNumber,
    },
  })
}

type LoginParams = {
  mobile: string
  password: string
  captchaId: any
  captchaData: any
}
/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postLoginAPI = (data: LoginParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/api/client/auth/login',
    data,
  })
}

type Logingenerate = {
  captchaId: any
}
/**
 * 获取图形验证码
 * @param data 请求参数
 */
export const generate = (data: Logingenerate) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/captcha/generate?captchaId=' + data.captchaId,
    data,
  })
}
type Logincheck = {
  data: any
  captchaId: any
}
/**
 * 验证图形验证码
 * @param data 请求参数
 */
export const check = (data: Logincheck, query: any) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/captcha/check?captchaId=' + query.captchaId,
    data,
  })
}
/**
 * 是否开启验证码
 * @param data 请求参数
 */
export const iscaptcha = () => {
  return http<any>({
    method: 'GET',
    url: '/api/client/auth/is-captcha',
  })
}

type smscode = {
  mobile: any
  captchaId: any
  codeId: any
  track: any
}
/**
 * 发送验证码
 * @param data 请求参数
 */
export const sendcode = (data: smscode) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/captcha/send-sms-code',
    data,
  })
}

type onregister = {
  mobile: any
  code: any
  codeId: any
  password: any
}
/**
 * 注册
 * @param data 请求参数
 */
export const mobilelogin = (data: onregister) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/auth/mobile-login',
    data,
  })
}
/**
 * 手机号登录
 * @param data 请求参数
 */
export const registermobile = (data: onregister) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/auth/reg-by-mobile',
    data,
  })
}
type onreset = {
  mobile: any
  code: any
  codeId: any
  newPassword: any
  confirmPassword: any
}
/**
 * 修改密码
 * @param data 请求参数
 */
export const resetpassword = (data: onreset) => {
  return http<any>({
    method: 'POST',
    url: '/api/client/auth/change-password-by-mobile',
    data,
  })
}
